package yannuo.web.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

@WebServlet("/login1")
public class LoginServlet1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setHeader("Access-Control-Allow-Origin","*");
        resp.setHeader("Access-Control-Allow-Credentials","true");

        String userName = req.getParameter("uname");
        String password = req.getParameter("pwd");
        System.out.println("userName = " + userName);
        System.out.println("password = " + password);
        HttpSession session = req.getSession();
        System.out.println(session.getId());

        if (userName.equals("test") && password.equals("222")){
            session.setAttribute("user",userName);
            resp.getWriter().print("ok");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
